﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "QWidget"
#include "QTreeWidget"
#include "once_trigger/connect_page/connect_page.h"
#include "once_trigger/wave/base_wave_widget.h"
#include "libdaq/backend/usb/usb_backend.h"
#include "once_trigger/once_trigger_thread/once_trigger_thread.h"

#include "libdaq/backend/usb_server/usb_server.h"
using DeviceAddress = uint8_t;
using DeviceMap = std::map<DeviceAddress, std::shared_ptr<libdaq::backend::LockzhinerUSBBackend> >;
using BusNumber = uint8_t;
using BusDeviceMap = std::map<BusNumber, DeviceMap>;
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
  MainWindow(QWidget *parent = nullptr);
  ~MainWindow();
  void UpdatePlotData(const std::vector<std::vector<float> > &data);
  void UpdateAutoScale();
private slots:
  void ConnectStatusSlot(bool status, ConnectPage::ConnectType type);
  void ClickConnectAction();
  void ClickStartADCCollectionAction();
  void ClickUpdateConfig();
  void ClickSoftwareTrigger();
  void ClickStopADCCollection();
private:
  void InitWaveWidget();

private:
  Ui::MainWindow *ui;
  QSharedPointer<OnceTriggerADCThread> once_trigger_adc_thread_; // 单次触发采集数据线程
  // QSharedPointer<ScrollModeADCThread> scroll_mode_adc_thread_; // 滚动模式采集数据线程

  QSharedPointer<ConnectPage> connect_page_; // 连接页面
  QSharedPointer<libdaq::device::LockzhinerBaseDevice> base_device_;
  QSharedPointer<BaseWaveWidget> base_wave_widget_; // 波形显示控件
  std::shared_ptr<libdaq::backend::LockzhinerBaseBackend> base_backend_ = nullptr; // 服务端
  libdaq::backend::USBOption* usb_option_=nullptr; // USB属性
  std::unique_ptr<libdaq::backend::LockzhinerUSBServer> usb_server_; // USB服务器

  int connected_count = 0;  // 连接设备个数

};
#endif // MAINWINDOW_H
